#include "AboutDlg.h"

#include <widgets/SImageButton.h>

#include <QHBoxLayout>
#include <QLabel>
#include <QVBoxLayout>

#include "core/ImageMgr.h"
#include "core/StyleMgr.h"

AboutDlg::AboutDlg(QWidget* parent /*= nullptr*/) : SPopupWindow(parent) {
  setWindowFlag(Qt::FramelessWindowHint);
  setAttribute(Qt::WA_TranslucentBackground);
  setFixedSize(512, 368);
  setTitle(tr("关于qeubee"));

  QVBoxLayout* mainLayout = contentLayout();
  mainLayout->setSpacing(0);
  mainLayout->addStretch();
  // logo
  QHBoxLayout* logoLayout = new QHBoxLayout();
  logoLayout->addStretch();
  QLabel* logo = new QLabel(this);
  SImage* logoImg = ImgMgr::instance().image("guiframe_app_logo_about");
  if (logoImg) {
    logo->setPixmap(QPixmap::fromImage(*logoImg));
  }
  logoLayout->addWidget(logo);
  logoLayout->addStretch();
  mainLayout->addLayout(logoLayout);
  mainLayout->addSpacing(12);

  // 联系电话
  QHBoxLayout* phoneLayout = new QHBoxLayout;
  phoneLayout->addStretch();
  QLabel* phone =
      new QLabel(QString("<font style='font-size:12px'; color=#%1>%2</font>")
                     .arg(StyleMgr::instance().color("TitleWord").rgb(), 0, 16)
                     .arg(tr("Contact us 400-119-9898")),
                 this);
  phoneLayout->addWidget(phone);
  phoneLayout->addStretch();
  mainLayout->addLayout(phoneLayout);
  mainLayout->addSpacing(25);

  // 已升级到最新版本
  QHBoxLayout* verLayout = new QHBoxLayout;
  verLayout->addStretch();
  QLabel* version = new QLabel(tr("已升级到最新版本(1.0.0.3)"), this);
  verLayout->addWidget(version);
  verLayout->addStretch();
  mainLayout->addLayout(verLayout);
  mainLayout->addSpacing(35);

  // 版本号、更新记录
  QHBoxLayout* upgradeInfoLayout = new QHBoxLayout();
  upgradeInfoLayout->addStretch();
  QLabel* curVer = new QLabel(
      QString("<font style='font-size:12px'; color=#%1>%2</font>")
          .arg(StyleMgr::instance().color("SupportingWord").rgb(), 0, 16)
          .arg(tr("当前版本:V1.0.0.3")),
      this);
  QLabel* upgradeHistory =
      new QLabel(QString("<font style='font-size:12px'; color=#%1>%2</font>")
                     .arg(StyleMgr::instance().color("TitleWord").rgb(), 0, 16)
                     .arg(tr("更新记录")),
                 this);
  upgradeInfoLayout->addWidget(curVer);
  upgradeInfoLayout->addSpacing(10);
  upgradeInfoLayout->addWidget(upgradeHistory);
  upgradeInfoLayout->addStretch();
  mainLayout->addLayout(upgradeInfoLayout);
  mainLayout->addSpacing(10);

  // 备案、版权信息
  QHBoxLayout* companyInfoLayout = new QHBoxLayout();
  companyInfoLayout->addStretch();
  QString str =
      QString(
          "<a href=\"\"><font style='font-size:12px'; color=#%1>%2</font></a>")
          .arg(StyleMgr::instance().color("SupportingWord").rgb(), 0, 16)
          .arg(tr("浙金信备〔2021〕2号"));
  QLabel* cert = new QLabel(str, this);
  QLabel* copyright = new QLabel(
      QString("<font style='font-size:12px'; color=#%1>%2</font>")
          .arg(StyleMgr::instance().color("SupportingWord").rgb(), 0, 16)
          .arg(tr("Copyright ©2013-2019 SUMSCOPE L.P. All Rights Reserved.")),
      this);
  companyInfoLayout->addWidget(cert);
  companyInfoLayout->addSpacing(10);
  companyInfoLayout->addWidget(copyright);
  companyInfoLayout->addStretch();
  mainLayout->addLayout(companyInfoLayout);
  mainLayout->addStretch();
}